#include <QColorDialog>
#include "ColorFrame.h"

namespace Domy {

ColorFrame::ColorFrame(QWidget *parent)
    : QFrame(parent),
      m_color(Qt::black)
{
    updateDisplay();
}

ColorFrame::~ColorFrame()
{

}

void ColorFrame::setColor(const QColor &color)
{
    if (m_color != color) {
        m_color = color;
        updateDisplay();

        emit signalColorChanged(color);
    }
}

QColor ColorFrame::getColor() const
{
    return m_color;
}

void ColorFrame::mouseReleaseEvent(QMouseEvent *event)
{
    m_color = QColorDialog::getColor(m_color, parentWidget(), tr("Color Picker"));

    updateDisplay();

    emit signalColorChanged(m_color);
}

void ColorFrame::updateDisplay()
{
    this->setStyleSheet(QString("background-color: rgb(%1, %2, %3);"
                                "border: 2px solid black;")
                        .arg(m_color.red()).arg(m_color.green()).arg(m_color.blue()));
}


} // namespace Domy
